home *** CD-ROM | disk | FTP | other *** search
- // mfnptr.cpp -- Member function pointers
-
- //#include <stream.hpp>
- #include <iostream.h>
- #include <iomanip.h>
-
- class firstClass {
- private:
- int count;
- public:
- firstClass() { count = 0; }
- int access(void);
- };
-
- int (firstClass::*myfnptr)(void);
-
- main()
- {
- int i;
- firstClass fc;
-
- cout << "\nCall access the normal way:\n";
- for (i = 0; i < 9; i++)
- // cout << dec(fc.access(), 8);
- cout << setw(8) << dec << fc.access();
-
- cout << "\n\nCall access via the member function pointer\n";
- myfnptr = firstClass::access;
- for (i = 0; i < 9; i++)
- // cout << dec((fc.*myfnptr)(), 8);
- cout << setw(8) << dec << (fc.*myfnptr)();
-
- cout << "\n\nMember function pointer and a dynamic instance\n";
- firstClass *fp = new firstClass;
- for (i = 0; i < 9; i++)
- // cout << dec((fp->*myfnptr)(), 8);
- cout << setw(8) << dec << (fp->*myfnptr)();
- }
-
- int firstClass::access(void)
- {
- return count++;
- }
-
-
- // Copyright (c) 1990 by Tom Swan. All rights reserved
- // Revision 1.00 Date: 11/25/1990 Time: 01:45 pm
-
- // Revision 1.01 Date: 07/08/1991 Time: 05:41 pm
- // Converted for Borland C++ 2.0
-
-